#ifndef _MESSAGEQUEUE_H_
#define _MESSAGEQUEUE_H_

#include <utillib/util/singleton.h>
#include <utillib/stl/queuelist.h>
#include <utillib/memory/memorypool.h>

#include <set>

namespace netlib
{
	namespace net
	{
		class Socket;
		
	};
	namespace packet
	{
		class Packet;
		
		class MessageQueue
		{
		public:
			struct MessageInfo
			{
				UINT messageID;
				LPARAM lparam;
				WPARAM wparam;
			};
		protected:
		struct FindMessageInfoByLPARAM : public std::binary_function < MessageInfo *, LPARAM , bool >
		{ 
			bool operator()( MessageInfo *messageInfo , LPARAM lparam ) const
			{
				if ( messageInfo->lparam == lparam )
					return ( true );
				return ( false );
			} 
		};
			MessageQueue();
		public:
			virtual ~MessageQueue();

			SingletonInstance( MessageQueue );

			void addIdleMessageID( UINT messageID );
			bool popIdle( netlib::packet::MessageQueue::MessageInfo *messageInfo );

			bool pop( netlib::packet::MessageQueue::MessageInfo *messageInfo );
			void push( UINT messageID, WPARAM wparam, LPARAM lparam  );

			void remove( LPARAM lparam );
		private:
			std::set < UINT > m_idleMessageIDList;
			utillib::stl::QueueList < MessageInfo * > m_idleMessageList;

			utillib::stl::QueueList < MessageInfo * > m_messageList;
			utillib::memory::MemoryPool < MessageInfo > m_messagInfoPool;
		};
	}
}

#endif